<template>
    <h2>添加页面</h2>
    <table border="1">
        <tr>
            <td>名称</td>
            <td>
                <input type="text" v-model="info.name" />
            </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="radio" v-model="info.state" :value="true"/>开房
                <input type="radio" v-model="info.state" :value="false"/>关房
            </td>
        </tr>
        <tr>
            <td>数量</td>
            <td>
                <input type="text" v-model="info.num"/>
            </td>
        </tr>
        <tr>
            <td>时间</td>
            <td>
                <input type="date" v-model="info.time" />
            </td>
        </tr>
        <tr>
            <td>描述</td>
            <td>
                <textarea v-model="info.info">

                </textarea>
            </td>
        </tr>
        <tr>
            <input type="button" value="添加 " @click="Add"/>
        </tr>
    </table>
</template>
<script setup lang="ts" >
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRoute,useRouter} from 'vue-router'
    const route=useRoute();
    const router=useRouter();
    const info=ref({
        name: "",
        state: true,
        num: 0,
        time: "",
        info: ""
    });

    const Add=()=>{
        axios.post("https://localhost:7272/api/Room/AddRoomState",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
                router.push({
                    name:"ShowRoomState"
                })
            }
            else if(res.data==-1){
                alert('此用户已存在');
            }
            else{
                alert('添加失败');
            }
        })
    }
</script>
